package app.sb.jly.com.ji_liang_yuan.activitys.ac;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;

import java.util.Arrays;
import java.util.Calendar;

import app.sb.jly.com.ji_liang_yuan.R;
import app.sb.jly.com.ji_liang_yuan.activitys.application.BaseApplication;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.Constants;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.DateUtil;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.PDALogUtils;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.SharedPreferencesUtils;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.UtilsLog;
import app.sb.jly.com.ji_liang_yuan.activitys.model.LoginModel;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//计重采集
public class JiZhongCaiJiActivity extends BaseActivity {

    @BindView(R.id.ac_jizhong_songjian_tv_1)
    TextView acJizhongSongjianTv1;
    @BindView(R.id.ac_jizhong_songjian_danwei)
    EditText acJizhongSongjianDanwei;
    @BindView(R.id.ac_jizhong_songjian_danwei_iv)
    ImageView acJizhongSongjianDanweiIv;
    @BindView(R.id.ac_jizhong_songjian_tv_2)
    TextView acJizhongSongjianTv2;
    @BindView(R.id.ac_jizhong_address)
    TextView acJizhongAddress;
    @BindView(R.id.ac_jizhong_adress_iv)
    ImageView acJizhongAdressIv;
    @BindView(R.id.ac_jizhong_zhan)
    EditText acJizhongZhan;
    @BindView(R.id.ac_jizhong_shoufeizhan)
    TextView acJizhongShoufeizhan;
    @BindView(R.id.ac_jizhong_rukou)
    TextView acJizhongRukou;
    @BindView(R.id.ac_jizhong_dao)
    EditText acJizhongDao;
    @BindView(R.id.ac_jizhong_jianding_ll_0)
    LinearLayout acJizhongJiandingLl0;
    @BindView(R.id.ac_jizhong_jianding_et)
    EditText acJizhongJiandingEt;
    @BindView(R.id.ac_jizhong_et_iv)
    ImageView acJizhongEtIv;
    @BindView(R.id.ac_jizhong_jianding_ll_1)
    LinearLayout acJizhongJiandingLl1;
    @BindView(R.id.ac_jizhong_wendu_tv)
    TextView acJizhongWenduTv;
    @BindView(R.id.ac_jizhong_wentu_et)
    EditText acJizhongWentuEt;
    @BindView(R.id.ac_jizhong_wendu_iv)
    ImageView acJizhongWenduIv;
    @BindView(R.id.ac_jizhong_zhizaodanwei_tv)
    TextView acJizhongZhizaodanweiTv;
    @BindView(R.id.ac_jizhong_zhizaodanwei_et)
    EditText acJizhongZhizaodanweiEt;
    @BindView(R.id.ac_jizhong_zhizaodanwei_iv)
    ImageView acJizhongZhizaodanweiIv;
    @BindView(R.id.ac_jizhong_jiliangqiju_tv)
    TextView acJizhongJiliangqijuTv;
    @BindView(R.id.ac_jizhong_jiliangqiju_et)
    EditText acJizhongJiliangqijuEt;
    @BindView(R.id.ac_jizhong_jiliangqiju_iv)
    ImageView acJizhongJiliangqijuIv;
    @BindView(R.id.ac_jizhong_xinghaoguige_tv)
    TextView acJizhongXinghaoguigeTv;
    @BindView(R.id.ac_jizhong_xinghaoguige_et)
    EditText acJizhongXinghaoguigeEt;
    @BindView(R.id.ac_jizhong_xinghaoguige_iv)
    ImageView acJizhongXinghaoguigeIv;
    @BindView(R.id.ac_jizhong_dengji_tv)
    TextView acJizhongDengjiTv;
    @BindView(R.id.ac_jizhong_dengji_et)
    EditText acJizhongDengjiEt;
    @BindView(R.id.ac_jizhong_dengji_iv)
    ImageView acJizhongDengjiIv;
    @BindView(R.id.ac_jizhong_date_tv)
    TextView acJizhongDateTv;
    @BindView(R.id.ac_jizhong_date_et)
    EditText acJizhongDateEt;
    @BindView(R.id.ac_jizhong_date_iv)
    ImageView acJizhongDateIv;
    @BindView(R.id.ac_jizhong_type_tv)
    TextView acJizhongTypeTv;
    @BindView(R.id.ac_jizhong_type_et)
    EditText acJizhongTypeEt;
    @BindView(R.id.ac_jizhong_type_iv)
    ImageView acJizhongTypeIv;
    @BindView(R.id.ac_jizhong_zhoushu_tv)
    TextView acJizhongZhoushuTv;
    @BindView(R.id.ac_jizhong_zhoushu_et)
    EditText acJizhongZhoushuEt;
    @BindView(R.id.ac_jizhong_zhoushu_iv)
    ImageView acJizhongZhoushuIv;
    @BindView(R.id.ac_jizhong_weight_tv)
    TextView acJizhongWeightTv;
    @BindView(R.id.ac_jizhong_weight_et)
    EditText acJizhongWeightEt;
    @BindView(R.id.ac_jizhong_weight_iv)
    ImageView acJizhongWeightIv;
    @BindView(R.id.ac_jizhong_user_tv)
    TextView acJizhongUserTv;
    @BindView(R.id.ac_jizhong_user_et)
    TextView acJizhongUserEt;
    @BindView(R.id.ac_jizhong_user_iv)
    ImageView acJizhongUserIv;
    @BindView(R.id.ac_jizhong_btn_jilinag_caiji)
    Button acJizhongBtnJilinagCaiji;
    @BindView(R.id.ac_jizhong_btn_wancheng)
    Button acJizhongBtnWanCheng;

    @BindView(R.id.ac_jizhong_fenduzhi_et)
    EditText acJizhongFenduzhiEt;
    @BindView(R.id.ac_jizhong_fenduzhi_iv)
    ImageView acJizhongFenduzhiIv;

    public LocationClient mLocationClient = null;
    @BindView(R.id.ac_jizhong_max_chengliang_et)
    EditText acJizhongMaxChengliangEt;
    @BindView(R.id.ac_jizhong_max_chengliang_iv)
    ImageView acJizhongMaxChengliangIv;
    @BindView(R.id.ac_jizhong_min_chengliang_et)
    EditText acJizhongMinChengliangEt;
    @BindView(R.id.ac_jizhong_min_chengliang_iv)
    ImageView acJizhongMinChengliangIv;
    @BindView(R.id.ac_jizhong_max_sudu_et)
    EditText acJizhongMaxSuduEt;
    @BindView(R.id.ac_jizhong_max_sudu_iv)
    ImageView acJizhongMaxSuduIv;
    @BindView(R.id.ac_jizhong_min_sudu_et)
    EditText acJizhongMinSuduEt;
    @BindView(R.id.ac_jizhong_min_sudu_iv)
    ImageView acJizhongMinSuduIv;
    @BindView(R.id.ac_jizhong_btn_check)
    Button acJizhongBtnCheck;
    @BindView(R.id.ac_jizhong_validity_et)
    EditText acJizhongValidityEt;
    @BindView(R.id.ac_jizhong_validity_iv)
    ImageView acJizhongValidityIv;
    @BindView(R.id.ac_jizhong_checkUser_et)
    EditText acJizhongCheckUserEt;
    @BindView(R.id.ac_jizhong_checkUser_iv)
    ImageView acJizhongCheckUserIv;
    @BindView(R.id.ac_zhizao_xukezheng_bh_tv)
    TextView acZhizaoXukezhengBhTv;
    @BindView(R.id.ac_zhizao_xukezheng_bh_et)
    EditText acZhizaoXukezhengBhEt;
    @BindView(R.id.ac_chuchang_bianhao_tv)
    TextView acChuchangBianhaoTv;
    @BindView(R.id.ac_chuchang_bianhao_et)
    EditText acChuchangBianhaoEt;


    private MyLocationListener myListener = new MyLocationListener();


    final Calendar ca = Calendar.getInstance();
    int mYear, mMonth, mDay;
    int mYear2, mMonth2, mDay2;
    final int DATE_DIALOG = 1;
    final int DATE_DIALOG2 = 2;


    int in_type = 0;
    String type0 = "";
    String type = "高速检定";
    String zhizaodanwei = "";
    String carModel = "";
    int zhoushu = 0, zhoushuA = 0, zhoushuB = 0;
    int weight = 0, weightA = 0, weightB = 0;

    boolean isFirst = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ji_zhong_cai_ji);
        ButterKnife.bind(this);
        setTopTitle("主界面");
//        setBackBtn();

        zhizaodanwei = getIntent().getStringExtra("zhizaodanwei");
        UtilsLog.e("zhizaodanwei=======" + zhizaodanwei);
//        acJizhongZhizaodanweiEt.setText(zhizaodanwei);
        in_type = getIntent().getIntExtra("in_type", 0);
//        carModel = getIntent().getStringExtra("carModel");
        zhoushu = getIntent().getIntExtra("zhoushu", 0);
        weight = getIntent().getIntExtra("result", 0);
        UtilsLog.e("in_type=======" + in_type);
        UtilsLog.e("zhoushu=======" + zhoushu);
        UtilsLog.e("weight=======" + weight);
        if (in_type == 1) {
            //多轴刚性
//            acJizhongTypeEt.setText("多轴刚性");
            type0 = "多轴刚性";
            BaseApplication.myCheckDataModel.setZhoushu0(String.valueOf(zhoushu));
            BaseApplication.myCheckDataModel.setZhongliang0(String.valueOf(weight));
        } else if (in_type == 2) {
            //铰接挂车
//            acJizhongTypeEt.setText("铰接挂车");
            type0 = "铰接挂车";
            BaseApplication.myCheckDataModel.setZhoushu1(String.valueOf(zhoushu));
            BaseApplication.myCheckDataModel.setZhongliang1(String.valueOf(weight));
        } else if (in_type == 3) {
            //多轴刚性和铰接挂车
//            acJizhongTypeEt.setText("多轴刚性和铰接挂车");
            type0 = "多轴刚性和铰接挂车";
            zhoushuA = getIntent().getIntExtra("zhoushuA", 0);
            zhoushuB = getIntent().getIntExtra("zhoushuB", 0);
            weightA = getIntent().getIntExtra("resultA", 0);
            weightB = getIntent().getIntExtra("resultB", 0);
            BaseApplication.myCheckDataModel.setZhoushu0(String.valueOf(zhoushuA));
            BaseApplication.myCheckDataModel.setZhoushu1(String.valueOf(zhoushuB));
            BaseApplication.myCheckDataModel.setZhongliang0(String.valueOf(weightA));
            BaseApplication.myCheckDataModel.setZhongliang1(String.valueOf(weightB));
            UtilsLog.e("zhoushu0=======" + getIntent().getExtras().getString("zhoushuA"));
            UtilsLog.e("zhoushu1=======" + getIntent().getExtras().getString("zhoushuB"));
            UtilsLog.e("weight0=======" + getIntent().getExtras().getString("weightA"));
            UtilsLog.e("weight1=======" + getIntent().getExtras().getString("weightB"));
        }
//        acJizhongZhoushuEt.setText(zhoushu);
//        acJizhongWeightEt.setText(weight);
//        BaseApplication.myCheckDataModel.setZhoushu0(String.valueOf(zhoushu));
//        BaseApplication.myCheckDataModel.setZhoushu1(String.valueOf(zhoushu));
        type = getIntent().getStringExtra("type");
        setAddType(type);
        UtilsLog.e("type=======" + type);
        acJizhongAddress.setText(type);


        //        BaseApplication.myCheckDataModel.setJiandingdidian(acJizhongJiandingEt.getText().toString().trim());
//        if (BaseApplication.myCheckDataModel != null) {
//            if (!TextUtils.isEmpty(BaseApplication.myCheckDataModel.getJiandingdidian())) {
//                acJizhongJiandingEt.setText(BaseApplication.myCheckDataModel.getJiandingdidian());
//            }
//        }

//        BaseApplication.myCheckDataModel.setType0(acJizhongTypeEt.getText().toString());
//        BaseApplication.myCheckDataModel.setType1(acJizhongTypeEt.getText().toString());
        BaseApplication.myCheckDataModel.setType0(type0);
        BaseApplication.myCheckDataModel.setType1(type0);

        setLeftTxt("返回", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mYear = ca.get(Calendar.YEAR);
        mMonth = ca.get(Calendar.MONTH);
        mDay = ca.get(Calendar.DAY_OF_MONTH);
        mYear2 = ca.get(Calendar.YEAR);
        mMonth2 = ca.get(Calendar.MONTH);
        mDay2 = ca.get(Calendar.DAY_OF_MONTH);

        acJizhongDateEt.setText(DateUtil.getTodayDate3());
        String[] d = DateUtil.getTodayDate3().split("\\.");
        UtilsLog.e("d====" + Arrays.toString(d));
        String cd = DateUtil.getTodayDate_add_one_year2(Integer.valueOf(d[0]), Integer.valueOf(d[1]), Integer.valueOf(d[2]));
        UtilsLog.e("cd====" + cd);
        BaseApplication.myCheckDataModel.setYouxiaoqi(cd);
        acJizhongValidityEt.setText(cd);
        LoginModel model = SharedPreferencesUtils.getRemeber_name_pwd(this);
        acJizhongUserEt.setText(model.getName());

        acJizhongJiliangqijuEt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    BaseApplication.myCheckDataModel.setJiliangqijumingcheng(acJizhongJiliangqijuEt.getText().toString().trim());
                }
            }
        });
        acJizhongXinghaoguigeEt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    BaseApplication.myCheckDataModel.setXinhaoguige(acJizhongXinghaoguigeEt.getText().toString().trim());
                }
            }
        });
//        acJizhongValidityEt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
//                if (!hasFocus) {
//                    BaseApplication.myCheckDataModel.setYouxiaoqi(acJizhongValidityEt.getText().toString().trim());
//                }
//            }
//        });
    }

    @OnClick({R.id.ac_jizhong_songjian_tv_1, R.id.ac_jizhong_songjian_danwei_iv, R.id.ac_jizhong_adress_iv, R.id.ac_jizhong_shoufeizhan, R.id.ac_jizhong_rukou, R.id.ac_jizhong_dao, R.id.ac_jizhong_et_iv, R.id.ac_jizhong_wendu_tv, R.id.ac_jizhong_wendu_iv, R.id.ac_jizhong_zhizaodanwei_tv, R.id.ac_jizhong_zhizaodanwei_iv, R.id.ac_jizhong_jiliangqiju_tv, R.id.ac_jizhong_jiliangqiju_iv, R.id.ac_jizhong_xinghaoguige_iv, R.id.ac_jizhong_dengji_tv, R.id.ac_jizhong_dengji_iv, R.id.ac_jizhong_date_tv, R.id.ac_jizhong_date_iv, R.id.ac_jizhong_type_tv, R.id.ac_jizhong_type_iv, R.id.ac_jizhong_zhoushu_tv, R.id.ac_jizhong_zhoushu_iv, R.id.ac_jizhong_weight_tv, R.id.ac_jizhong_weight_iv, R.id.ac_jizhong_user_tv, R.id.ac_jizhong_user_iv, R.id.ac_jizhong_btn_jilinag_caiji, R.id.ac_jizhong_fenduzhi_iv, R.id.ac_jizhong_btn_wancheng,
            R.id.ac_jizhong_max_chengliang_iv, R.id.ac_jizhong_min_chengliang_iv, R.id.ac_jizhong_max_sudu_iv, R.id.ac_jizhong_min_sudu_iv,
            R.id.ac_jizhong_btn_check, R.id.ac_jizhong_validity_iv, R.id.ac_jizhong_checkUser_iv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_jizhong_max_chengliang_iv:
                showMyDialog3(Constants.zuida_chengliang, R.id.ac_jizhong_max_chengliang_iv);
                break;
            case R.id.ac_jizhong_min_chengliang_iv:
                showMyDialog3(Constants.zuixiao_chengliang, R.id.ac_jizhong_min_chengliang_iv);
                break;
            case R.id.ac_jizhong_max_sudu_iv:
                showMyDialog3(Constants.zuigao_sudu, R.id.ac_jizhong_max_sudu_iv);
                break;
            case R.id.ac_jizhong_min_sudu_iv:
                showMyDialog3(Constants.zuidi_sudu, R.id.ac_jizhong_min_sudu_iv);
                break;
            case R.id.ac_jizhong_fenduzhi_iv:
                //分度值
                showMyDialog(Constants.fen_du_zhi, R.id.ac_jizhong_fenduzhi_iv);
                break;
            case R.id.ac_jizhong_songjian_danwei_iv:
                //送检单位
                if (type.equals("高速检定")) {
                    showMyDialog(Constants.song_jian_dan_wei, R.id.ac_jizhong_songjian_danwei_iv);
                } else if (type.equals("非现检定")) {
//                    showMyDialog(Constants.song_jian_dan_wei2, R.id.ac_jizhong_songjian_danwei_iv);
                }
                break;
            case R.id.ac_jizhong_adress_iv:
                //检定type
                showMyDialog(Constants.jian_ding, R.id.ac_jizhong_adress_iv);
                break;
            case R.id.ac_jizhong_rukou:
                // 入口--出口
                showMyDialog(Constants.ru_chu_kou, R.id.ac_jizhong_rukou);
                break;
            case R.id.ac_jizhong_dao:
                //车道
//                showMyDialog(Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO, R.id.ac_jizhong_dao);
                break;
            case R.id.ac_jizhong_et_iv:
                if (mLocationClient != null) {
                    mLocationClient.stop();
                }
                isFirst = false;
                mLocationClient.restart();
                acJizhongJiandingEt.setText("");
                break;
            case R.id.ac_jizhong_zhizaodanwei_iv:
                //制造单位
                if (type.equals("高速检定")) {
                    showMyDialog(Constants.zhi_zao_dan_wei, R.id.ac_jizhong_zhizaodanwei_iv);
                } else if (type.equals("非现检定")) {
                    showMyDialog(Constants.zhi_zao_dan_wei2, R.id.ac_jizhong_zhizaodanwei_iv);
                }
                break;
            case R.id.ac_jizhong_jiliangqiju_tv:
                break;
            case R.id.ac_jizhong_jiliangqiju_iv:
                //计量器具名称
                showMyDialog(Constants.ji_liang_qi_ju_ming_cheng, R.id.ac_jizhong_jiliangqiju_iv);
                break;
            case R.id.ac_jizhong_xinghaoguige_iv:
                //型号/规格
                showMyDialog(Constants.xing_hao_gui_ge, R.id.ac_jizhong_xinghaoguige_iv);
                break;
            case R.id.ac_jizhong_dengji_iv:
                //车辆总重量准确度等级
                showMyDialog2(Constants.che_liang_zhun_que_deng_ji, R.id.ac_jizhong_dengji_iv);
                break;
            case R.id.ac_jizhong_date_iv:
                //日期
                showDialog(DATE_DIALOG);
                break;
            case R.id.ac_jizhong_validity_iv:
                //有效期至
                showDialog(DATE_DIALOG2);
                break;
            case R.id.ac_jizhong_type_iv:
                //参考车辆类型
                showMyDialog2(Constants.can_kao_che_liang_lei_xing, R.id.ac_jizhong_type_iv);
                break;
            case R.id.ac_jizhong_zhoushu_iv:
                //参考车辆轴数
                showMyDialog2(Constants.zhou_shu, R.id.ac_jizhong_zhoushu_iv);
                break;
            case R.id.ac_jizhong_btn_jilinag_caiji:
                //计量采集
//                BaseApplication.myCheckDataModel.setZhongliang0(
//                        !TextUtils.isEmpty(acJizhongWeightEt.getText().toString().trim()) ? acJizhongWeightEt.getText().toString().trim() : "0");
//                BaseApplication.myCheckDataModel.setZhongliang1(
//                        !TextUtils.isEmpty(acJizhongWeightEt.getText().toString().trim()) ? acJizhongWeightEt.getText().toString().trim() : "0");
//                BaseApplication.myCheckDataModel.setZhongliang0(String.valueOf(weight));
//                BaseApplication.myCheckDataModel.setZhongliang1(String.valueOf(weight));
//                BaseApplication.myCheckDataModel.setWendu(
//                        !TextUtils.isEmpty(acJizhongWentuEt.getText().toString().trim()) ? acJizhongWentuEt.getText().toString().trim() + "℃" : "25℃");
                if (!TextUtils.isEmpty(acJizhongWentuEt.getText().toString().trim())) {
                    String ww = acJizhongWentuEt.getText().toString().trim();
                    if (ww.contains("℃")) {

                    } else {
                        ww = ww + "℃";
                    }
                    BaseApplication.myCheckDataModel.setWendu(ww);
                } else {
                    BaseApplication.myCheckDataModel.setWendu("150℃");
                }
                BaseApplication.myCheckDataModel.setCheckUser(
                        !TextUtils.isEmpty(acJizhongCheckUserEt.getText().toString().trim()) ? acJizhongCheckUserEt.getText().toString().trim() : "");
                BaseApplication.myCheckDataModel.setUname(
                        !TextUtils.isEmpty(acJizhongUserEt.getText().toString().trim()) ? acJizhongUserEt.getText().toString().trim() : "");
                BaseApplication.myCheckDataModel.setZhidaodanwei(acJizhongZhizaodanweiEt.getText().toString().trim());
                BaseApplication.myCheckDataModel.setSongjiandaiwei(acJizhongSongjianDanwei.getText().toString().trim());
                BaseApplication.myCheckDataModel.setZhizaoxukezhengbianhao(acZhizaoXukezhengBhEt.getText().toString().trim());
                BaseApplication.myCheckDataModel.setChuchangbianhoa(acChuchangBianhaoEt.getText().toString().trim());

                BaseApplication.myCheckDataModel.setZuidachengliang(!TextUtils.isEmpty(acJizhongMaxChengliangEt.getText().toString().trim()) ? acJizhongMaxChengliangEt.getText().toString().trim() : "0");
                BaseApplication.myCheckDataModel.setZuixiaochengliang(!TextUtils.isEmpty(acJizhongMinChengliangEt.getText().toString().trim()) ? acJizhongMinChengliangEt.getText().toString().trim() : "0");
                BaseApplication.myCheckDataModel.setZuigaosudu(!TextUtils.isEmpty(acJizhongMaxSuduEt.getText().toString().trim()) ? acJizhongMaxSuduEt.getText().toString().trim() : "0km/h");
                BaseApplication.myCheckDataModel.setZuidisudu(!TextUtils.isEmpty(acJizhongMinSuduEt.getText().toString().trim()) ? acJizhongMinSuduEt.getText().toString().trim() : "0km/h");
                BaseApplication.myCheckDataModel.setYouxiaoqi(acJizhongValidityEt.getText().toString().trim());
                String date = acJizhongDateEt.getText().toString();
                BaseApplication.myCheckDataModel.setShijian(date);
//                String[] d = date.split("-");
//                String[] d = date.split("\\.");
//                UtilsLog.e("d====" + Arrays.toString(d));
//                String cd = DateUtil.getTodayDate_add_one_year2(Integer.valueOf(d[0]), Integer.valueOf(d[1]), Integer.valueOf(d[2]));
//                UtilsLog.e("cd====" + cd);
//                BaseApplication.myCheckDataModel.setYouxiaoqi(cd);

                if ("高速检定".equals(type)) {
                    String str = acJizhongZhan.getText().toString().trim() + "收费站" + acJizhongRukou.getText().toString().trim() + acJizhongDao.getText().toString().trim() + "道";
                    BaseApplication.myCheckDataModel.setJiandingdidian(str);
                    BaseApplication.myCheckDataModel.setTxt_name(str);
                } else if ("非现检定".equals(type)) {
                    BaseApplication.myCheckDataModel.setJiandingdidian(acJizhongJiandingEt.getText().toString().trim());
                    BaseApplication.myCheckDataModel.setTxt_name(acJizhongJiandingEt.getText().toString().trim());
                }

                UtilsLog.e("acJizhongJiandingEt====" + acJizhongJiandingEt.getText().toString().trim());
                Intent intent = new Intent(this, ShuJuJISuanActivity.class);
                intent.putExtra("in_type", in_type);
                startActivity(intent);

                break;
            case R.id.ac_jizhong_btn_wancheng:
                //完成采集
                finish();
                //生成报表
//                if (BaseApplication.myCheckDataModel != null) {
//                    setTxtContents(BaseApplication.myCheckDataModel.getTxt_name());
//                }
                break;
            case R.id.ac_jizhong_btn_check:
                //查看已存报表文件
                String dirUrl = Environment.getExternalStorageDirectory() + "/PDA_TXT/";
//             // 将文件夹按时间倒序排序
//                PDALogUtils.listFileSortByModifyTime(dirUrl);
                String path = "%2fPDA_TXT%2f";
                Uri uri = Uri.parse("content://com.android.externalstorage.documents/document/primary:" + path);
                Intent intent2 = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                intent2.addCategory(Intent.CATEGORY_OPENABLE);
//                intent.setType("text/plain");//想要展示的文件类型(txt)
                intent2.setType("*/*");//展示所有
                intent2.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri);
                startActivityForResult(intent2, 0);
                break;
            case R.id.ac_jizhong_checkUser_iv:
                //检验人员
                showMyDialog2(Constants.user, R.id.ac_jizhong_checkUser_iv);
                break;
        }
    }

    void setTxtContents(String fileName) {
        String str = "";
//        for (int i = 0; i < Constants.contents.length; i++) {
//            str += Constants.contents[i] + "\r\n";
//        }
//        UtilsLog.e(str);

        if (BaseApplication.myCheckDataModel == null) {
            return;
        }
        //多轴刚性和铰接挂车
        if (BaseApplication.myCheckDataModel.getType0().equals("多轴刚性")
                || BaseApplication.myCheckDataModel.getType0().equals("铰接挂车")) {
            str = BaseApplication.myCheckDataModel.getSongjiandaiwei() + "\r\n"
                    + BaseApplication.myCheckDataModel.getJiandingdidian() + "\r\n"
                    + BaseApplication.myCheckDataModel.getWendu() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhidaodanwei() + "\r\n"
                    + BaseApplication.myCheckDataModel.getJiliangqijumingcheng() + "\r\n"
                    + BaseApplication.myCheckDataModel.getXinhaoguige() + "\r\n"
                    + BaseApplication.myCheckDataModel.getFenduzhi() + "\r\n"

                    + BaseApplication.myCheckDataModel.getZuidachengliang() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuixiaochengliang() + "\r\n"

                    + BaseApplication.myCheckDataModel.getDengji() + "\r\n"

                    + BaseApplication.myCheckDataModel.getZuigaosudu() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuidisudu() + "\r\n"

                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"

                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"

                    + BaseApplication.myCheckDataModel.getType0() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhoushu0() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongliang0() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisuzhongxin00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisuzhongxin01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getGaosuzhognxin00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getGaosuzhognxin01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianzuo00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianzuo01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianyou00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianyou01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuidawucha1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getMPE1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getHege1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getUname() + "\r\n"
            ;
        } else {
            str = BaseApplication.myCheckDataModel.getSongjiandaiwei() + "\r\n"
                    + BaseApplication.myCheckDataModel.getJiandingdidian() + "\r\n"
                    + BaseApplication.myCheckDataModel.getWendu() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhidaodanwei() + "\r\n"
                    + BaseApplication.myCheckDataModel.getJiliangqijumingcheng() + "\r\n"
                    + BaseApplication.myCheckDataModel.getXinhaoguige() + "\r\n"
                    + BaseApplication.myCheckDataModel.getFenduzhi() + "\r\n"

                    + BaseApplication.myCheckDataModel.getZuidachengliang() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuixiaochengliang() + "\r\n"

                    + BaseApplication.myCheckDataModel.getDengji() + "\r\n"

                    + BaseApplication.myCheckDataModel.getZuigaosudu() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuidisudu() + "\r\n"

                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"

                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"

                    + BaseApplication.myCheckDataModel.getType0() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhoushu0() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongliang0() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisuzhongxin00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisuzhongxin01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getGaosuzhognxin00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getGaosuzhognxin01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianzuo00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianzuo01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianyou00() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianyou01() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuidawucha1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getMPE1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getHege1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getType1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhoushu1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongliang1() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisuzhongxin10() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisuzhongxin11() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin10() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin11() + "\r\n"
                    + BaseApplication.myCheckDataModel.getGaosuzhognxin10() + "\r\n"
                    + BaseApplication.myCheckDataModel.getGaosuzhognxin11() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianzuo10() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianzuo11() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianyou10() + "\r\n"
                    + BaseApplication.myCheckDataModel.getDisupianyou11() + "\r\n"
                    + BaseApplication.myCheckDataModel.getZuidawucha2() + "\r\n"
                    + BaseApplication.myCheckDataModel.getMPE2() + "\r\n"
                    + BaseApplication.myCheckDataModel.getHege2() + "\r\n"
                    + BaseApplication.myCheckDataModel.getUname() + "\r\n"
            ;
        }

        PDALogUtils.createTxtFile(fileName, str.getBytes(), this);

        Toast.makeText(this, "生成报表成功", Toast.LENGTH_LONG).show();
    }

    void setAddType(String text) {
        if ("高速检定".equals(text)) {
            acJizhongSongjianDanwei.setText(Constants.song_jian_dan_wei[1]);
            acJizhongJiandingLl0.setVisibility(View.VISIBLE);
            acJizhongJiandingLl1.setVisibility(View.GONE);
            acJizhongSongjianDanweiIv.setVisibility(View.VISIBLE);
//            String str = acJizhongZhan.getText().toString().trim() + "收费站" + acJizhongRukou.getText().toString().trim() + acJizhongDao.getText().toString().trim();
//            BaseApplication.myCheckDataModel.setJiandingdidian(str);
//            BaseApplication.myCheckDataModel.setTxt_name(acJizhongZhan.getText().toString().trim());
        } else {
            acJizhongJiandingLl0.setVisibility(View.GONE);
            acJizhongJiandingLl1.setVisibility(View.VISIBLE);
            acJizhongSongjianDanweiIv.setVisibility(View.GONE);
            mLocationClient = new LocationClient(getApplicationContext());
            //声明LocationClient类
            mLocationClient.registerLocationListener(myListener);
            //注册监听函数
            baiduMap();
            if (BaseApplication.myCheckDataModel != null) {
                if (!TextUtils.isEmpty(BaseApplication.myCheckDataModel.getJiandingdidian())) {
//                    acJizhongJiandingEt.setText(BaseApplication.myCheckDataModel.getJiandingdidian());
                } else {
                    mLocationClient.start();
                }
            }

//            mLocationClient.start();
        }
    }

    private void showMyDialog(String[] str, final int id) {
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("---showMyDialog==" + text + "===" + index);
                switch (id) {
                    case R.id.ac_jizhong_songjian_danwei_iv:
                        //送检单位
                        acJizhongSongjianDanwei.setText(text);
                        BaseApplication.myCheckDataModel.setSongjiandaiwei(text);
                        break;
                    case R.id.ac_jizhong_adress_iv:
                        //检定type
                        acJizhongAddress.setText(text);
                        setAddType(text);
//                        if ("高速检定".equals(text)) {
//                            acJizhongJiandingLl0.setVisibility(View.VISIBLE);
//                            acJizhongJiandingLl1.setVisibility(View.GONE);
//                            String str = acJizhongZhan.getText().toString().trim() + "收费站" + acJizhongRukou.getText().toString().trim() + acJizhongDao.getText().toString().trim();
//                            BaseApplication.myCheckDataModel.setJiandingdidian(str);
//                        } else {
//                            acJizhongJiandingLl0.setVisibility(View.GONE);
//                            acJizhongJiandingLl1.setVisibility(View.VISIBLE);
//                            mLocationClient = new LocationClient(getApplicationContext());
//                            //声明LocationClient类
//                            mLocationClient.registerLocationListener(myListener);
//                            //注册监听函数
//                            baiduMap();
//                            mLocationClient.start();
//                        }
                        break;
                    case R.id.ac_jizhong_rukou:
                        // 入口--出口
                        acJizhongRukou.setText(text);
                        break;
                    case R.id.ac_jizhong_dao:
                        //车道
                        acJizhongDao.setText(text);
                        break;
                    case R.id.ac_jizhong_zhizaodanwei_iv:
                        //制造单位
                        acJizhongZhizaodanweiEt.setText(text);
                        BaseApplication.myCheckDataModel.setZhidaodanwei(text);
                        break;
                    case R.id.ac_jizhong_jiliangqiju_iv:
                        //计量器具名称
                        acJizhongJiliangqijuEt.setText(text);
                        BaseApplication.myCheckDataModel.setJiliangqijumingcheng(text);
                        break;
                    case R.id.ac_jizhong_xinghaoguige_iv:
                        //型号/规格
                        acJizhongXinghaoguigeEt.setText(text);
                        BaseApplication.myCheckDataModel.setXinhaoguige(text);
                        break;
                    case R.id.ac_jizhong_dengji_iv:
                        //车辆总重量准确度等级
                        acJizhongDengjiEt.setText(text);
                        BaseApplication.myCheckDataModel.setDengji(text);
                        break;
                    case R.id.ac_jizhong_type_iv:
                        //参考车辆类型
                        acJizhongTypeEt.setText(text);
                        BaseApplication.myCheckDataModel.setType0(text);
                        BaseApplication.myCheckDataModel.setType1(text);
                        break;
                    case R.id.ac_jizhong_zhoushu_iv:
                        //参考车辆轴数
                        acJizhongZhoushuEt.setText(text);
                        BaseApplication.myCheckDataModel.setZhoushu0(text);
                        BaseApplication.myCheckDataModel.setZhoushu1(text);
                        break;
                    case R.id.ac_jizhong_fenduzhi_iv:
                        //分度值
                        acJizhongFenduzhiEt.setText(text);
                        BaseApplication.myCheckDataModel.setFenduzhi(text);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    private void showMyDialog2(String[] str, final int id) {
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("---showMyDialog=222=" + text + "===" + index);
                switch (id) {
                    case R.id.ac_jizhong_songjian_danwei_iv:
                        //送检单位
                        acJizhongSongjianDanwei.setText(text);
                        BaseApplication.myCheckDataModel.setSongjiandaiwei(text);
                        break;
                    case R.id.ac_jizhong_adress_iv:
                        //检定type
                        acJizhongAddress.setText(text);
                        setAddType(text);
//                        if ("高速检定".equals(text)) {
//                            acJizhongJiandingLl0.setVisibility(View.VISIBLE);
//                            acJizhongJiandingLl1.setVisibility(View.GONE);
//                            String str = acJizhongZhan.getText().toString().trim() + "收费站" + acJizhongRukou.getText().toString().trim() + acJizhongDao.getText().toString().trim();
//                            BaseApplication.myCheckDataModel.setJiandingdidian(str);
//                        } else {
//                            acJizhongJiandingLl0.setVisibility(View.GONE);
//                            acJizhongJiandingLl1.setVisibility(View.VISIBLE);
//                            mLocationClient = new LocationClient(getApplicationContext());
//                            //声明LocationClient类
//                            mLocationClient.registerLocationListener(myListener);
//                            //注册监听函数
//                            baiduMap();
//                            mLocationClient.start();
//                        }
                        break;
                    case R.id.ac_jizhong_rukou:
                        // 入口--出口
                        acJizhongRukou.setText(text);
                        break;
                    case R.id.ac_jizhong_dao:
                        //车道
                        acJizhongDao.setText(text);
                        break;
                    case R.id.ac_jizhong_zhizaodanwei_iv:
                        //制造单位
                        acJizhongZhizaodanweiEt.setText(text);
                        BaseApplication.myCheckDataModel.setZhidaodanwei(text);
                        break;
                    case R.id.ac_jizhong_jiliangqiju_iv:
                        //计量器具名称
                        acJizhongJiliangqijuEt.setText(text);
                        BaseApplication.myCheckDataModel.setJiliangqijumingcheng(text);
                        break;
                    case R.id.ac_jizhong_xinghaoguige_iv:
                        //型号/规格
                        acJizhongXinghaoguigeEt.setText(text);
                        BaseApplication.myCheckDataModel.setXinhaoguige(text);
                        break;
                    case R.id.ac_jizhong_dengji_iv:
                        //车辆总重量准确度等级
                        acJizhongDengjiEt.setText(text);
                        BaseApplication.myCheckDataModel.setDengji(text);
                        break;
                    case R.id.ac_jizhong_type_iv:
                        //参考车辆类型
                        acJizhongTypeEt.setText(text);
                        BaseApplication.myCheckDataModel.setType0(text);
                        BaseApplication.myCheckDataModel.setType1(text);
                        break;
                    case R.id.ac_jizhong_zhoushu_iv:
                        //参考车辆轴数
                        acJizhongZhoushuEt.setText(text);
                        BaseApplication.myCheckDataModel.setZhoushu0(text);
                        BaseApplication.myCheckDataModel.setZhoushu1(text);
                        break;
                    case R.id.ac_jizhong_fenduzhi_iv:
                        //分度值
                        acJizhongFenduzhiEt.setText(text);
                        BaseApplication.myCheckDataModel.setFenduzhi(text);
                        break;
                    case R.id.ac_jizhong_checkUser_iv:
                        //检验人员
                        acJizhongCheckUserEt.setText(text);
                        BaseApplication.myCheckDataModel.setCheckUser(text);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    private void showMyDialog3(String[] str, final int id) {
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("---showMyDialog=333=" + text + "===" + index);
                switch (id) {
                    case R.id.ac_jizhong_max_chengliang_iv:
                        acJizhongMaxChengliangEt.setText(text);
                        BaseApplication.myCheckDataModel.setZuidachengliang(text);
                        break;
                    case R.id.ac_jizhong_min_chengliang_iv:
                        acJizhongMinChengliangEt.setText(text);
                        BaseApplication.myCheckDataModel.setZuixiaochengliang(text);
                        break;
                    case R.id.ac_jizhong_max_sudu_iv:
                        acJizhongMaxSuduEt.setText(text);
                        BaseApplication.myCheckDataModel.setZuigaosudu(text);
                        break;
                    case R.id.ac_jizhong_min_sudu_iv:
                        acJizhongMinSuduEt.setText(text);
                        BaseApplication.myCheckDataModel.setZuidisudu(text);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    void baiduMap() {
        LocationClientOption option = new LocationClientOption();
        option.setIsNeedAddress(true);
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
//可选，设置定位模式，默认高精度
//LocationMode.Hight_Accuracy：高精度；
//LocationMode. Battery_Saving：低功耗；
//LocationMode. Device_Sensors：仅使用设备；
//LocationMode.Fuzzy_Locating, 模糊定位模式；v9.2.8版本开始支持，可以降低API的调用频率，但同时也会降低定位精度；

        option.setCoorType("bd09ll");
//可选，设置返回经纬度坐标类型，默认GCJ02
//GCJ02：国测局坐标；
//BD09ll：百度经纬度坐标；
//BD09：百度墨卡托坐标；
//海外地区定位，无需设置坐标类型，统一返回WGS84类型坐标

//        option.setFirstLocType(FirstLocType.SPEED_IN_FIRST_LOC);
//可选，首次定位时可以选择定位的返回是准确性优先还是速度优先，默认为速度优先
//可以搭配setOnceLocation(Boolean isOnceLocation)单次定位接口使用，当设置为单次定位时，setFirstLocType接口中设置的类型即为单次定位使用的类型
//FirstLocType.SPEED_IN_FIRST_LOC:速度优先，首次定位时会降低定位准确性，提升定位速度；
//FirstLocType.ACCUARACY_IN_FIRST_LOC:准确性优先，首次定位时会降低速度，提升定位准确性；

        option.setScanSpan(1000);
//可选，设置发起定位请求的间隔，int类型，单位ms
//如果设置为0，则代表单次定位，即仅定位一次，默认为0
//如果设置非0，需设置1000ms以上才有效

        option.setOpenGps(true);
//可选，设置是否使用卫星定位，默认false
//使用高精度和仅用设备两种定位模式的，参数必须设置为true

        option.setLocationNotify(true);
//可选，设置是否当卫星定位有效时按照1S/1次频率输出卫星定位结果，默认false

        option.setIgnoreKillProcess(false);
//可选，定位SDK内部是一个service，并放到了独立进程。
//设置是否在stop的时候杀死这个进程，默认（建议）不杀死，即setIgnoreKillProcess(true)

        option.SetIgnoreCacheException(false);
//可选，设置是否收集Crash信息，默认收集，即参数为false

        option.setWifiCacheTimeOut(5 * 60 * 1000);
//可选，V7.2版本新增能力
//如果设置了该接口，首次启动定位时，会先判断当前Wi-Fi是否超出有效期，若超出有效期，会先重新扫描Wi-Fi，然后定位

        option.setEnableSimulateGps(false);
//可选，设置是否需要过滤卫星定位仿真结果，默认需要，即参数为false

        option.setNeedNewVersionRgc(true);
//可选，设置是否需要最新版本的地址信息。默认需要，即参数为true

        mLocationClient.setLocOption(option);
//mLocationClient为第二步初始化过的LocationClient对象
//需将配置好的LocationClientOption对象，通过setLocOption方法传递给LocationClient对象使用
//更多LocationClientOption的配置，请参照类参考中LocationClientOption类的详细说明
    }

    @OnClick(R.id.ac_jizhong_fenduzhi_iv)
    public void onViewClicked() {
    }


    public class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            //此处的BDLocation为定位结果信息类，通过它的各种get方法可获取定位相关的全部结果
            //以下只列举部分获取经纬度相关（常用）的结果信息
            //更多结果信息获取说明，请参照类参考中BDLocation类中的说明

            double latitude = location.getLatitude();    //获取纬度信息
            double longitude = location.getLongitude();    //获取经度信息
            float radius = location.getRadius();    //获取定位精度，默认值为0.0f
//
//            UtilsLog.e("纬度===" + latitude + "");
//            UtilsLog.e("经度===" + longitude + "");

            String coorType = location.getCoorType();
            //获取经纬度坐标类型，以LocationClientOption中设置过的坐标类型为准

            int errorCode = location.getLocType();
            //获取定位类型、定位错误返回码，具体信息可参照类参考中BDLocation类中的说明
//            String addrstr = location.getAddrStr();
//            String Address = location.getAddress().country + "-" + location.getAddress().province
//                    + "-" + location.getAddress().city
//                    + "-" + location.getAddress().district;
//            String myAddress = location.getAddress().address;
//            UtilsLog.e("errorCode==" + errorCode);
////            UtilsLog.e("addrstr==" + addrstr);
////            UtilsLog.e("Address==" + Address);
//            UtilsLog.e("getCountry==" + location.getCountry());
//            UtilsLog.e("getProvince==" + location.getProvince());
//            UtilsLog.e("getCity==" + location.getCity());
//            UtilsLog.e("getDistrict==" + location.getDistrict());
//            UtilsLog.e("getStreet==" + location.getStreet());
//            UtilsLog.e("getStreetNumber==" + location.getStreetNumber());
            if (isFirst == false) {
                if (!TextUtils.isEmpty(location.getCity()) && !TextUtils.isEmpty(location.getDistrict())
                        && !TextUtils.isEmpty(location.getStreet()) && !TextUtils.isEmpty(location.getStreetNumber())
                        ) {
//                    if (type.equals("高速检定")){
//                        acJizhongJiandingEt.setText(location.getCity() + location.getDistrict() +
//                                location.getStreet() + location.getStreetNumber());
//                        BaseApplication.myCheckDataModel.setJiandingdidian(acJizhongJiandingEt.getText().toString().trim());
//                        BaseApplication.myCheckDataModel.setTxt_name(acJizhongJiandingEt.getText().toString().trim());
//                    }else if (type.equals("非现检定")){
//                        acJizhongJiandingEt.setText("");
//                    }
                    acJizhongJiandingEt.setText(location.getCity() + location.getDistrict() +
                            location.getStreet() + location.getStreetNumber());
                    BaseApplication.myCheckDataModel.setJiandingdidian(acJizhongJiandingEt.getText().toString().trim());
                    BaseApplication.myCheckDataModel.setTxt_name(acJizhongJiandingEt.getText().toString().trim());
                }
                isFirst = true;
            }

        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mLocationClient != null) {
            mLocationClient.stop();
        }
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DATE_DIALOG:
                return new DatePickerDialog(this, mdateListener, mYear, mMonth, mDay);
            case DATE_DIALOG2:
                return new DatePickerDialog(this, mdateListener2, mYear2, mMonth2, mDay2);
        }
        return null;
    }

    /**
     * 设置日期 利用StringBuffer追加
     */
    public void display(TextView tv) {
//        tv.setText(new StringBuffer().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay)
//                .append(" "));
        String str = mYear + "." + (mMonth + 1) + "." + mDay;
        UtilsLog.e("======" + DateUtil.getDateForSurplus3(str));
        tv.setText(DateUtil.getDateForSurplus3(str));
        BaseApplication.myCheckDataModel.setShijian(acJizhongDateEt.getText().toString());
    }

    public void display2(TextView tv) {
//        tv.setText(new StringBuffer().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay)
//                .append(" "));
        String str = mYear2 + "." + (mMonth2 + 1) + "." + mDay2;
        UtilsLog.e("======" + DateUtil.getDateForSurplus3(str));
        tv.setText(DateUtil.getDateForSurplus3(str));
        BaseApplication.myCheckDataModel.setYouxiaoqi(acJizhongValidityEt.getText().toString());
    }

    private DatePickerDialog.OnDateSetListener mdateListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                              int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            display(acJizhongDateEt);
        }
    };
    private DatePickerDialog.OnDateSetListener mdateListener2 = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                              int dayOfMonth) {
            mYear2 = year;
            mMonth2 = monthOfYear;
            mDay2 = dayOfMonth;
            display2(acJizhongValidityEt);
        }
    };
}
